package com.base.monitor.model.model.biz.cfg.vo;

import cn.hutool.core.util.StrUtil;
import com.base.monitor.model.model.biz.cfg.entity.Indicator;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class IndicatorVo extends Indicator {
    private String parseScaleStr; // 将parseScale转为中文说明

    public IndicatorVo(Indicator indicator) {
        BeanUtils.copyProperties(indicator, this);
        this.parseScaleStr = getDescFromScaleStr(indicator.getParseScale());
    }

    public String getDescFromScaleStr(String parseScale) {
        if (StrUtil.isBlank(parseScale)) {
            return "";
        }
        String[] split = parseScale.split(",");
        StringBuilder sb = new StringBuilder();
        for (String s : split) {
            sb.append(getDescFromSingleScale(Integer.parseInt(s))).append(",");
        }
        return sb.substring(0, sb.toString().length() - 1);
    }

    private String getDescFromSingleScale(int scale) {
        if (scale == 2) {
            return "二进制";
        }
        if (scale == 10) {
            return "十进制";
        }
        if (scale == 0) {
            return "ascii码";
        }
        return "";
    }
}
